package com.sikao.app.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.CategoryAttrBean;
import com.sikao.app.ui.AddGoodsStepTwoActivity;

public class MllAddStepPricesTypeFiveItemAdapter extends BaseAdapter {

    private List<CategoryAttrBean.ResBean.AttrBean> objects = new ArrayList<CategoryAttrBean.ResBean.AttrBean>();

    private Context context;
    private LayoutInflater layoutInflater;
    private  MllAddStepPricesTypeFiveItemAdapterOnClickListener mllAddStepPricesTypeFiveItemAdapterOnClickListener;

    public MllAddStepPricesTypeFiveItemAdapter(Context context,List<CategoryAttrBean.ResBean.AttrBean> objects,MllAddStepPricesTypeFiveItemAdapterOnClickListener mllAddStepPricesTypeFiveItemAdapterOnClickListener) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.objects=objects;
        this.mllAddStepPricesTypeFiveItemAdapterOnClickListener=mllAddStepPricesTypeFiveItemAdapterOnClickListener;
    }

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public CategoryAttrBean.ResBean.AttrBean getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.mll_add_step_prices_type_five_item, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews(getItem(position), (ViewHolder) convertView.getTag(),position);
        return convertView;
    }

    private void initializeViews(CategoryAttrBean.ResBean.AttrBean object, ViewHolder holder,int position) {
        //TODO implement
        holder.rlMallStepPricesTypeFive.setTag(position);
        if (AddGoodsStepTwoActivity.canEdit){
            holder.rlMallStepPricesTypeFive.setEnabled(true);
            holder.rlMallStepPricesTypeFive.setClickable(true);
        }else{
            holder.rlMallStepPricesTypeFive.setEnabled(false);
            holder.rlMallStepPricesTypeFive.setClickable(false);
        }

        holder.rlMallStepPricesTypeFive.setOnClickListener(mllAddStepPricesTypeFiveItemAdapterOnClickListener);
        holder.tvName.setText(object.getName());
        holder.tvValue.setText(object.getContent());
    }

    protected class ViewHolder {
        private RelativeLayout rlMallStepPricesTypeFive;
    private TextView tvName;
    private TextView tvValue;

        public ViewHolder(View view) {
            rlMallStepPricesTypeFive = (RelativeLayout) view.findViewById(R.id.rl_mall_step_prices_type_five);
            tvName = (TextView) view.findViewById(R.id.tv_name);
            tvValue = (TextView) view.findViewById(R.id.tv_value);
        }
    }
    //点击回调
    public static abstract class MllAddStepPricesTypeFiveItemAdapterOnClickListener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            myOnClick((Integer) v.getTag());
        }
        public abstract void  myOnClick(int position);
    }
}
